package hpu.bitenergy.servlet;

import hpu.bitenergy.Factory.Factory;
import hpu.bitenergy.IFactory.IFactory;
import hpu.bitenergy.List.GetList;
import hpu.bitenergy.util.QueryHelper;
import hpu.bitenergy.util.StringHelper;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mongodb.DBObject;

public class expert_YTservlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String expert_name = new String(request.getParameter("expert_name")
				.getBytes("ISO_8859-1"), "UTF-8");
		System.out.println("yun:"+expert_name);
		IFactory fad=Factory.GetIFactory("L");
		GetList li=fad.GetListInstance();
		List<DBObject> list=li.getQueryList(QueryHelper.expert_name(StringHelper.AddOneKong(expert_name)),QueryHelper.getKey(true));
		List<List<Object>> names=StringHelper.Getyuntukeys(list);
		System.out.println("yun:"+names);
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/json");
		PrintWriter out = response.getWriter();

		out.write(names.toString());
		out.flush();
		out.close();
	}

}
